import api from '../../api'
import tipBox from "../../plugins";

const state = {
    products: []
}
const actions = {
    loadProductList({ commit, rootState }, params) {
        api.loadProductsByPid(params)
            .then(({ success, result: { sortFilter, wall: { docs } } }) => {
                if (!success) {
                    return Promise.reject("请求失败");
                }
                commit("setproducts", docs)
                if (rootState.sortList.length == 0) {
                    commit("setsortList", sortFilter, {
                        root: true
                    });
                }
            }).catch((error) => {
                // console.log(error);
                tipBox.showMsg("数据加载失败", "error", 2000);
            })
    }
}
const mutations = {
    setproducts(state, nv) {
        state.products = nv;
    }
}

export default {
    namespaced: true, // 开启命名空间
    state,
    actions,
    mutations
}